package com.teachoa.util;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings({"rawtypes", "unchecked"})
public class Maps {
	
	private Map map;
	
	public Maps() {
		map = new HashMap();
	}
	
	public Maps(Map map) {
		this.map = map;
	}
	
	public Maps put(Object key, Object value) {
		map.put(key, value);
		return this;
	}
	
	public Map build() {
		return map;
	}
	
	public static Map newHashMap() {
		return new HashMap();
	}
	
	public static Map newHashMap(Object...objs) {
		return put(newHashMap(), objs);
	}
	
	public static Map put(Map map, Object...objs) {
		int len = objs.length;
		if(objs!=null&&len>0) {
			for(int i=0;i<len;i=i+2) {
				if(i+1<len) map.put(objs[i], objs[i+1]);
				else map.put(objs[i], null);
			}
		}
		return map;
	}
	
	public static Map put(Map target, Map source) {
		target.putAll(source);
		return target;
	}
	
	public static Map changeKey(Map map, Object org, Object now) {
		copyValue(map, org, now).remove(org);
		return map;
	}
	
	public static Map copyValue(Map map, Object org, Object now) {
		map.put(now, map.get(org));
		return map;
	}
	
}
